<template>
  <div class="add_table_css">
    <el-button plain @click="addEducation" class="btn_css_newadd">新增资历信息</el-button>
    <!-- 新增资历信息的弹框 -->
    <el-dialog title="新增资历信息" :visible.sync="dialogFormVisible" width="40%" center>
      <el-form
        label-width="150px"
        :model="qualifyTable"
        :rules="rules"
        ref="qualifyTable"
        class="demo-ruleForm add_education_css"
      >
        <el-form-item label="专业技术系列" prop="technicalSeries">
          <el-select v-model="qualifyTable.technicalSeries">
            <el-option label="汉" value="汉"></el-option>
            <el-option label="满" value="满"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="资格专业" prop="professionalQualification">
          <el-select v-model="qualifyTable.professionalQualification">
            <el-option label="汉" value="汉"></el-option>
            <el-option label="满" value="满"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="职务任职资格" prop="postQualification">
          <el-select v-model="qualifyTable.postQualification">
            <el-option label="汉" value="汉"></el-option>
            <el-option label="满" value="满"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="获取资格时间" prop="qualificationTime">
          <el-date-picker type="date" v-model="qualifyTable.qualificationTime"></el-date-picker>
        </el-form-item>
        <el-form-item label="聘任日期" prop="appointmentDate">
          <el-date-picker type="date" v-model="qualifyTable.appointmentDate"></el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer add_footer_btn_css">
        <el-button plain @click="addOk('qualifyTable')" class="btn_css_bord">保存</el-button>
        <el-button plain @click="dialogFormVisible = false" class="btn_css_bord">关闭</el-button>
      </div>
    </el-dialog>
    <!-- 表格 -->
    <el-container>
      <el-table :data="tableData" style="width: 100%;">
        <el-table-column type="index" label="序号" width="50"></el-table-column>
        <el-table-column prop="technicalSeries" label="现专业技术系列" width="150"></el-table-column>
        <el-table-column prop="professionalQualification" label="现资格专业" width="130"></el-table-column>
        <el-table-column prop="postQualification" label="职务任职资格" width="150"></el-table-column>
        <el-table-column prop="qualificationTime" label="获取资格时间 " width="130"></el-table-column>
        <el-table-column prop="appointmentDate" label=" 聘任日期 " width="130"></el-table-column>
        <el-table-column label="操作" width="220">
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.row)" plain size="small" class="btn_css_si">上传附件</el-button>
            <el-button @click="handleClick(scope.row)" plain size="small" class="btn_css_si">查看附件</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-container>
    <!-- 分页 -->
    <div class="block page_css">
      <el-pagination
        layout="prev, pager, next"
        :total="total"
        :page-size="limit"
        @current-change="change"
        @prev-click="prev"
        @next-click="next"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
export default {
   data() {
    return {
      page: 1,
      limit: 5,
      total: 0,
      staffId: 7,

      tableData: [],
      dialogFormVisible: false,
      qualifyTable: {
        technicalSeries: "",
        professionalQualification: "",
        postQualification: "",
        qualificationTime: "",
        appointmentDate: ""
      },
      rules: {
        technicalSeries: [
          { required: true, message: "请输入毕业院校", trigger: "blur" }
        ],
        professionalQualification: [
          { required: true, message: "请输入毕业院校", trigger: "blur" }
        ],
        postQualification: [
          { required: true, message: "请输入毕业院校", trigger: "blur" }
        ],
        qualificationTime: [
          { required: true, message: "请选择入学时间", trigger: "change" }
        ],
        appointmentDate: [
          { required: true, message: "请选择毕业时间", trigger: "change" }
        ]
      }
    };
  },
  methods: {
    /* 页面渲染 */
    getCon(){
      this.$axios({
        url:'/qualification/list',
        method:'post',
        data:{
          staffId: this.staffId,
          page: this.page,
          limit: this.limit,
        }
      }).then(res => {
        // console.log(res);
        this.tableData = res.data.data;
        this.total = res.data.count;
      })
    },
    /* 新增 */
    addEducation() {
      this.dialogFormVisible = true;
    },
    addOk(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.$axios({
            url: "/qualification/add",
            method: "post",
            data: {
              // id: this.staffId,
              staffId: this.staffId,
              technicalSeries: this.qualifyTable.technicalSeries,
              professionalQualification: this.qualifyTable.professionalQualification,
              qualificationTime: this.qualifyTable.qualificationTime,
              appointmentDate: this.qualifyTable.appointmentDate,
              postQualification: this.qualifyTable.postQualification,
            }
          }).then(res => {
            console.log(res);
            this.getCon();
            this.dialogFormVisible = false;
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },

    /* 分页渲染 */
    change(page) {
      this.page = page;
      this.getCon();
    },
    prev() {
      this.page--;
      this.getCon();
    },
    next() {
      this.page++;
      this.getCon();
    },

    handleClick(row) {
      this.dialogFormVisible2 = true;
      console.log(row);
    },
  },
  // mounted() {
  //   sessionStorage.setItem("activeIndex", 1);
  // }
  mounted() {
    this.getCon();
    sessionStorage.setItem("fName", "Process4");
  }
};
</script>
<style scoped lang="less">
.page_css {
  margin: 10px;
  text-align: right;
}
.el-table {
  font-size: 13px;
}
.btn_css_newadd {
  background-color: #f7f7f7;
  border: 1px solid #eee;
  text-align: center;
}
.btn_css_er {
  background-color: #f7f7f7;
  border: 1px solid #eee;
  width: 60px;
  height: 30px;
  text-align: center;
}
.btn_css_si {
  background-color: #f7f7f7;
  border: 1px solid #eee;
  width: 80px;
  height: 30px;
  text-align: center;
}
.btn_css_bord {
  background-color: #f7f7f7;
  border: 1px solid #eee;
  width: 80px;
  height: 40px;
  font-size: 14px;
  text-align: center;
}
.add_education_css {
  width: 370px;
  margin-left: 40px;
}
.add_footer_btn_css {
  margin: 0 auto;
}
.add_table_css {
  border: 1px solid #eee;
  // height: 600px;
  padding: 20px;
}
</style>